﻿using UnityEngine;
using System.Collections;

public class Bullet : MonoBehaviour {

	public Type bulletType;//子弹类型
	public float speed=13;//子弹移动速度

	void Start ()
	{
		//根据子弹类型决定飞行方向
		Vector2 dir = bulletType == Type.player ? Vector2.up : Vector2.down;
		//设置刚体速度，让子弹飞起来
		GetComponent<Rigidbody2D> ().velocity = dir * speed;
	}

	public enum Type //子弹类别类型（枚举）
	{
		player,
		enemy
	}
	//当触发器进入
	void OnTriggerEnter2D(Collider2D other)//other是对方的碰撞器
	{
		print (other.name);
		//销毁对方物体

		Plane plane= other.GetComponent<Plane> ();//找飞机组件，玩家分机，敌人飞机都可以
		if (plane != null) 
		{
			plane.Gethurt (1);//让飞机受到1点伤害
		} else
		{
			if(other.name!="Range")
			{
				Destroy (other.gameObject);//没有找到飞机就直接销毁对方物体
			};
		}
		//销毁子弹自己

		Destroy (this.gameObject);
	}
}

